package coml.jiyun.hp.wanandroid.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import coml.jiyun.hp.wanandroid.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class SystemFragment extends Fragment {


    private TabLayout mTab;
    private ViewPager mVp;
    private ArrayList<Fragment> fragments;
    private ArrayList<String> list;

    public SystemFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.fragment_system, container, false);
        initView(inflate);
        return inflate;
    }

    private void initView(View inflate) {
        mTab = inflate.findViewById(R.id.sytem_tab);
        mVp = inflate.findViewById(R.id.system_vp);

        fragments = new ArrayList<>();
        fragments.add(new SystemTwoFragment());
        fragments.add(new NaviFragment());

        list = new ArrayList<>();
        list.add("体系");
        list.add("导航");

        mVp.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return list.get(position);
            }
        });
        mTab.setupWithViewPager(mVp);
    }

}